﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;

namespace Beat_em_Up.Scenes
{
    public class Menu
    {
        Texture2D background, cursor;

        Game1 game;
        Button start, quit, credits;

        private bool wasStarted = false;
        private int alphaValue = 0;

        Vector2 foo = new Vector2();

        public Menu(ContentManager Content)
        {
            game = new Game1();

            background = Content.Load<Texture2D>("MenuImages/background");

            start = new Button(Content.Load<Texture2D>("MenuImages/start_off"), Content.Load<Texture2D>("MenuImages/start_on"), Content.Load<Texture2D>("MenuImages/start_click"));
            start.obj_menu.X = (game.graphics.PreferredBackBufferWidth / 2) - (start.obj_menu.Width / 2);
            start.obj_menu.Y = game.graphics.PreferredBackBufferHeight / 2;

            credits = new Button(Content.Load<Texture2D>("MenuImages/credits_off"), Content.Load<Texture2D>("MenuImages/credits_on"), Content.Load<Texture2D>("MenuImages/start_click"));
            credits.obj_menu.X = start.obj_menu.X;
            credits.obj_menu.Y = start.obj_menu.Y + start.obj_menu.Y / 4;

            quit = new Button(Content.Load<Texture2D>("MenuImages/quit_off"), Content.Load<Texture2D>("MenuImages/quit_on"), Content.Load<Texture2D>("MenuImages/start_click"));
            quit.obj_menu.X = credits.obj_menu.X;
            quit.obj_menu.Y = credits.obj_menu.Y + credits.obj_menu.Y / 5;

            cursor = Content.Load<Texture2D>("MenuImages/cursor");
            
            //Console.WriteLine("1 - " + start.obj_menu.Y + " 2 - " + credits.obj_menu.Y + " 3 - " + quit.obj_menu.Y);

            wasStarted = true;
        }

        public void Update(GameTime gameTime, MouseState currentMouse)
        {
            start.Update(gameTime, currentMouse);
            credits.Update(gameTime, currentMouse);
            quit.Update(gameTime, currentMouse);

            if (start.wasClicked == true)
            {
                Manager.current_Scene = Manager.Screens.SCENE_01;
            }

            if (credits.wasClicked == true)
            {
                Manager.current_Scene = Manager.Screens.CREDITS;
            }

            if (quit.wasClicked == true)
            {
                Manager.current_Scene = Manager.Screens.EXIT;
            }

            if (wasStarted == true)
            {
                alphaValue += 2;
            }

            foo.X = currentMouse.X;
            foo.Y = currentMouse.Y; 

            Console.WriteLine(currentMouse);
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(background, new Rectangle(0, 0, background.Width, background.Height), new Color(255, 255, 255, (byte)MathHelper.Clamp(alphaValue, 0, 255)));
            if (alphaValue >= 255)
            {
                start.Draw(gameTime, spriteBatch);
                credits.Draw(gameTime, spriteBatch);
                quit.Draw(gameTime, spriteBatch);

                spriteBatch.Draw(cursor, new Rectangle((int)foo.X, (int)foo.Y, cursor.Width, cursor.Height), Color.White);
            }
        }
    }
}
